﻿using System;

namespace Eflong.MonitoringLib.Common
{
    public static class StructDemo
    {
        public static DataUpdateStruct DataUpdateDemo( )
        {
            DataUpdateStruct aDataUpdateStruct = new DataUpdateStruct( );
            aDataUpdateStruct.m_nCoalMineId = 1;
            aDataUpdateStruct.m_dwNumOfData = 2;
            aDataUpdateStruct.m_dwMethodType = VizClientServer.VCS_MT_UPDATEDATA;
            aDataUpdateStruct.m_dwBufSize = aDataUpdateStruct.dwBufSize( );
            aDataUpdateStruct.m_MonUnitData = new MonUnitData[ 2 ];
            MonUnitData aData1 = new MonUnitData( );
            aData1.Init( );
            aData1.m_szId = "0101".ToCharArray( );
            Random rd = new Random( );
            aData1.m_fValue = ( float )( rd.Next( 0 , 30 ) / 10.0 );
            if ( aData1.m_fValue < 1.0 )
            {
                aData1.m_nState = Convert.ToByte( 16 );
            }
            else
            {
                aData1.m_nState = Convert.ToByte( 18 );
            }

            KWConvert.SetDateTimeToSystemTime( DateTime.Now , ref aData1.m_stData );
            KWConvert.SetDateTimeToSystemTime( DateTime.Now , ref aData1.m_stStateChange );
            aDataUpdateStruct.m_MonUnitData[ 0 ] = aData1;

            MonUnitData aData2 = new MonUnitData( );
            aData2.Init( );
            aData2.m_szId = "0102".ToCharArray( );
            aData2.m_fValue = rd.Next( 0 , 2 );
            aData2.m_nState = Convert.ToByte( aData2.m_fValue );
            KWConvert.SetDateTimeToSystemTime( DateTime.Now , ref aData2.m_stData );
            KWConvert.SetDateTimeToSystemTime( DateTime.Now , ref aData2.m_stStateChange );
            aDataUpdateStruct.m_MonUnitData[ 1 ] = aData2;
            return aDataUpdateStruct;
        }

        public static DefinitionUpdateStruct DefinitionDemo( )
        {
            DefinitionUpdateStruct aDefUpdate = new DefinitionUpdateStruct( );
            uint dwBufSize = aDefUpdate.dwBufSize( );
            aDefUpdate.m_nCoalMineId = 1;
            aDefUpdate.m_dwNumOfDef = 2;
            aDefUpdate.m_dwBufSize = aDefUpdate.dwBufSize( );
            aDefUpdate.m_dwMethodType = VizClientServer.VCS_MT_UPDATEDEFINITION;

            DefinitionStruct analogDef = new DefinitionStruct( );
            analogDef.m_szId = "0101".ToCharArray( );

            analogDef.m_szName = "1201工作面瓦斯".ToCharArray( );
            analogDef.m_nModality = 1;
            analogDef.m_nType = ( byte )1;
            analogDef.analogDef.m_szUnit = "%CH4".ToCharArray( );
            analogDef.analogDef.m_fLowerBound = 0;
            analogDef.analogDef.m_fUpperBound = 4.0f;
            analogDef.analogDef.m_fLowerLimit = 0;
            analogDef.analogDef.m_fUpperLimit = 1.0f;
            analogDef.analogDef.m_byRecChangeAmp = 0;

            DefinitionStruct digitalDef = new DefinitionStruct( );
            digitalDef.m_szId = "0102".ToCharArray( );
            digitalDef.m_szName = "1201回风大巷".ToCharArray( );
            digitalDef.m_nType = ( byte )13;
            digitalDef.m_nModality = 2;
            digitalDef.digitalDef.m_bTriState = true;
            digitalDef.digitalDef.m_szStateName0 = "开".ToCharArray( );
            digitalDef.digitalDef.m_szStateName1 = "停风".ToCharArray( );
            digitalDef.digitalDef.m_szStateName2 = "停风".ToCharArray( );

            aDefUpdate.m_MonUnitDef = new DefinitionStruct[ 2 ];
            aDefUpdate.m_MonUnitDef[ 0 ] = analogDef;
            aDefUpdate.m_MonUnitDef[ 1 ] = digitalDef;

            return aDefUpdate;
        }
    }
}